﻿@model IEnumerable<QuanLyGiaoVuUI.Models.LopMonHoc.LopMonHocViewModel>

@{
    Layout = "~/Views/Shared/_blueWhaleLayout.cshtml";
}
@using QuanLyGiaoVuDAL.DTO;
@{Html.RenderPartial("LopMonHocMenuPartial");}
@{
    HocKyDTO hocKy = (HocKyDTO)(ViewData["HocKyTiepTheo"]);
    }

<div id="main" class="grid_10">
    <!--  start page-heading -->
    <div id="page-heading" class="box round first grid">
        <h2>Danh sách lớp lý thuyết @hocKy.TenHocKyDayDu</h2>
        <!-- end page-heading -->
        <div class="block">
            @*<input type="button" name="btnXuatFile" id="btnXuatFile" value="Xuất danh sách" />*@

            <table class="data display datatable">
                <tr>
                    <th class="sorting"></th>
                    <th class="sorting">
                        @Html.DisplayNameFor(model => model.MaLopMonHoc)
                    </th>
                    <th class="sorting">Tên Môn học
                    </th>
                    <th class="sorting">Họ tên giảng viên 1
                    </th>
                    <th class="sorting">
                        @Html.DisplayNameFor(model => model.SiSoToiDa)
                    </th>
                    <th class="sorting">
                        @Html.DisplayNameFor(model => model.LoaiLop)
                    </th>
                    <th class="sorting">
                        @Html.DisplayNameFor(model => model.LopSinhVienId)
                    </th>
                    <th class="sorting">
                        @Html.DisplayNameFor(model => model.GiangVienXacNhan)
                    </th>
                    <th class="sorting">
                        @Html.DisplayNameFor(model => model.DaPhanHoi)
                    </th>
                    <th class="sorting">
                        @Html.DisplayNameFor(model => model.GhiChu)
                    </th>
                    <th class="sorting">Tùy chọn
                    </th>
                </tr>
                @{int count = 0;
                  var dsLopLyThuyet = Model.Where(lop => lop.LoaiLop == 0);
                }
                @foreach (var item in dsLopLyThuyet)
                {
                    <tr class="gradeA @(++count % 2 == 0 ? "even" : "odd")">
                        <td>
                            <input type="checkbox" value="@item.LopMonHocId" />
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.MaLopDayDu)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.MonHoc.TenMonHoc)
                        </td>
                        <td>
                           @item.GiangVien1.GetTenVaHocVi()
                        </td>

                        <td>
                            @Html.DisplayFor(modelItem => item.SiSoToiDa)
                        </td>
                        <td>
                            @(item.LoaiLop == 0 ? "Lý Thuyết" : "Thực Hành")
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.LopSinhVien.TenLop)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.GiangVienXacNhan)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.DaPhanHoi)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.GhiChu)
                        </td>
                        <td>
                            @Html.ActionLink("Sửa", "CapNhat", "LopMonHoc", new { id = item.LopMonHocId }, null) |
                            <a href="javascript:;" class="btnXoa" data-id="@item.LopMonHocId">Xóa</a>
                        </td>
                    </tr>
                }

            </table>
        </div>
    </div>

    <div id="page-heading" class="box round first grid">
        <h2>Danh sách lớp thực hành @hocKy.TenHocKyDayDu</h2>
        <!-- end page-heading -->
        <div class="block">
            <table class="data display datatable">
                <tr>
                    <th class="sorting"></th>
                    <th class="sorting">
                        @Html.DisplayNameFor(model => model.MaLopMonHoc)
                    </th>
                    <th class="sorting">Tên Môn học
                    </th>
                    <th class="sorting">Họ tên giảng viên 1
                    </th>
                    <th class="sorting">Họ tên giảng viên 2
                    </th>
                    <th class="sorting">
                        @Html.DisplayNameFor(model => model.SiSoToiDa)
                    </th>
                    <th class="sorting">
                        @Html.DisplayNameFor(model => model.LoaiLop)
                    </th>
                    <th class="sorting">
                        @Html.DisplayNameFor(model => model.LopSinhVienId)
                    </th>
                    <th class="sorting">
                        @Html.DisplayNameFor(model => model.GiangVienXacNhan)
                    </th>
                    <th class="sorting">
                        @Html.DisplayNameFor(model => model.DaPhanHoi)
                    </th>
                    <th class="sorting">Tùy chọn
                    </th>
                </tr>
                @{count = 0;
                  var dsLopThucHanh = Model.Where(lop => lop.LoaiLop != 0);
                }
                @foreach (var item in dsLopThucHanh)
                {
                    <tr class="gradeA @(++count % 2 == 0 ? "even" : "odd")">
                        <td>
                            <input type="checkbox" value="@item.LopMonHocId" />
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.MaLopDayDu)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.MonHoc.TenMonHoc)
                        </td>
                        <td>
                            @item.GiangVien1.GetTenVaHocVi()
                        </td>
                        @if (item.MaGiangVien2 != null)
                        {
                            <td>
                                @item.GiangVien2.GetTenVaHocVi()
                            </td>
                        }
                        else
                        {
                            <td></td>
                        }
                        <td>
                            @Html.DisplayFor(modelItem => item.SiSoToiDa)
                        </td>
                        <td>
                            @(item.LoaiLop == 0 ? "Lý Thuyết" : (item.LoaiLop == 1 ? "Thực Hành (HT1)" : "Thực hành (HT2)"))
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.LopSinhVien.TenLop)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.GiangVienXacNhan)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.DaPhanHoi)
                        </td>
                        <td>
                            @Html.ActionLink("Sửa", "CapNhat", "LopMonHoc", new { id = item.LopMonHocId }, null) |
                            <a href="javascript:;" class="btnXoa" data-id="@item.LopMonHocId">Xóa</a>
                        </td>
                    </tr>
                }

            </table>
        </div>
    </div>
</div>
<div id="XuatFileDialog"></div>

<script>
    $(document).ready(function () {
        $("#XuatFileDialog").load("/LopMonHoc/XuatFileDialog", function () {
            $("#XuatFileDialog").dialog({
                autoOpen: false,
                title: "Xuất file excel",
                width: 500,
                height: 300,
                buttons: {
                    "Xuất file": function () {
                        $("#uploadTemplate").submit();
                    },
                    "Hủy": function () {
                        $("#XuatFileDialog").dialog("close");
                    }
                }
            });
        });
        $("#btnXuatFile").button().bind("click", function () {
            $("#XuatFileDialog").dialog("open");
        });

        $(".btnXoa").bind("click", function () {
            if (confirm("Xóa lớp này?")) {
                var lopMonHocId = $(this).data("id");
                var currentBtn = $(this);
                XoaLopMonHoc(lopMonHocId, function (data) {
                    if (data.success) {
                        ToastManager.showSuccessToast("Xóa lớp thành công.");
                        currentBtn.closest("tr").remove();
                    }
                    else
                        ToastManager.showStickyWarningToast(data.message);
                });
            }
        });
    });

    function XoaLopMonHoc(id, callback) {
        $.ajax({
            type: "POST",
            url: "/LopMonHoc/XoaLopMonHoc",
            data: {
                maLop: id
            },
            success: function (data) {
                if (callback && typeof (callback) == "function") {
                    callback(data);
                }
            }
        });
    }
</script>
